#include "../Logger/log.hpp"
using namespace LoggerSpace;
void test1()
{
    // 使用日志管理器来获取同步日志器
    LOG_DEBUG("logger1", "%s", "我是logger1...");
    LOG_INFO("logger1", "%s", "我是logger1...");
    LOG_WARN("logger1", "%s", "我是logger1...");
    LOG_ERROR("logger1", "%s", "我是logger1...");
    LOG_FATAL("logger1", "%s", "我是logger1...");
    LOG_UNKNOWN("logger1", "%s", "我是logger1...");

    // 使用日志管理器来获取异步日志器
    LOG_DEBUG("logger2", "%s", "我是logger2...");
    LOG_INFO("logger2", "%s", "我是logger2...");
    LOG_WARN("logger2", "%s", "我是logger2...");
    LOG_ERROR("logger2", "%s", "我是logger2...");
    LOG_FATAL("logger2", "%s", "我是logger2...");
    LOG_UNKNOWN("logger2", "%s", "我是logger2...");

    // 使用默任日志器
    LOGD("%s", "我是默认日志器...");
    LOGI("%s", "我是默认日志器...");
    LOGW("%s", "我是默认日志器...");
    LOGE("%s", "我是默认日志器...");
    LOGF("%s", "我是默认日志器...");
    LOGU("%s", "我是默认日志器...");
}
void test2()
{
    // 测试滚动文件以大小
    GobalLoggerBuilder go;
    go.buildLoggerName("logger3");
    go.buildLevelLimits();
    go.buildFormater();
    // go.buildLoggerType();
    go.buildLoggerType(Logger::LoggerType::LOGGER_ASYNC); // 异步
    go.buildSink<RollSinkBySize>("./Log/RS");             // 512k作为分割
    go.build();
    int N = 1000000;
    int cnt = 0;
    while (cnt < N)
    {
        LOG_FATAL("logger3", "%s%d", "我是logger3 ", cnt++);
    }
}
void test3()
{
    // 测试滚动文件以时间
    GobalLoggerBuilder go;
    go.buildLoggerName("logger4");
    go.buildLevelLimits();
    go.buildFormater();
    // go.buildLoggerType();
    go.buildLoggerType(Logger::LoggerType::LOGGER_ASYNC); // 异步
    go.buildSink<RollSinkByTime>("./Log/RT");             // 1s作为分割4
    go.build();
    int N = 10;
    int cnt = 0;
    while (cnt < N)
    {
        LOG_FATAL("logger4", "%s %d", "我是logger4 ", cnt++);
        sleep(1);
    }
}
void test4()
{
    // 测试网络服务器
    GobalLoggerBuilder go;
    go.buildLoggerName("logger5");
    go.buildLevelLimits();
    go.buildFormater();
    go.buildLoggerType();
    // go.buildLoggerType(Logger::LoggerType::LOGGER_ASYNC);//异步
    go.buildSink<WebSink>("43.139.114.179", 8888);
    go.build();
    int N = 500000;
    int cnt = 0;
    while (cnt < N)
    {
        LOG_FATAL("logger5", "%s %d", "测试..........................................", cnt++);
    }
}
void test5()
{
    LogMes mes("jjj", __LINE__, LogLevel::DEBUG, "root", "测试");
    Formater fm("%m%n");
    std::cout << fm.format(mes);
}
int main()
{
    //创建同步日志器
    GobalLoggerBuilder go;
    go.buildLoggerName("logger1");
    go.buildLevelLimits(); // 使用默认输出等级:debug
    go.buildFormater();    // 使用默认输出格式："[%d{%H:%M:%S}]%T[%t]%T[%p]%T[%c]%T[%f:%l]%T%m%n"
    go.buildLoggerType();  // 默认是同步日志器
    go.buildSink<FileSink>("./Log/file1.log");
    // go.buildSink<RollSinkBySize>("./Log/RS");
    // go.buildSink<WebSink>("43.139.114.179", 8888);
    go.build();
    // 异步日志器
    go.buildLoggerName("logger2");
    go.buildLevelLimits(LogLevel::FATAL);
    go.buildFormater("%f:%l%T%m%n");
    go.buildLoggerType(Logger::LoggerType::LOGGER_ASYNC);
    go.buildSink<FileSink>("./Log/file2.log");
    // go.buildSink<WebSink>("43.139.114.179", 8888);
     go.buildSink<FileSink>("./Log/file2.log");
     go.buildSink<RollSinkByTime>("./Log/RT");
    go.build();
    // test1();
    // test5();
    // test4();
    test1();
    return 0;
}
